{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import requests\n",
    "import base64\n",
    "import urllib\n",
    "import json\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.b2d8d6627dd3f6f72d1d087b34d7611c.315360000.1926500192.282335-23568040', 'expires_in': 2592000, 'session_key': '9mzdXUXENqZoWvlPr561UgI9SwMSgAvfxEqtLx0HetVKyWeATu9AKdMooDRLeD/4b/HKRQVwfgh7aJL8Vs95kr6//8oYgA==', 'access_token': '24.f199973d4cf54d07178315b4cb8eb300.2592000.1613732192.282335-23568040', 'scope': 'public brain_all_scope brain_body_analysis brain_body_attr brain_body_number brain_driver_behavior brain_body_seg brain_gesture_detect brain_body_tracking brain_hand_analysis wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': '0553f4e107263346cabdc20a08263ebb'}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=evgh41NK66XfnAEdg16ek95m&client_secret=x3zwNsmZUZPBwv693fHcyqMGO0p5dC1L'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'person_num': 126, 'log_id': 1785367073846641972}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "'''\n",
    "人流量统计（动态版）\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/body_num\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('人1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"area\":\"1,1,719,1,719,719,1,719\",\"case_id\":1,\"case_init\":\"false\",\"dynamic\":\"true\",\"image\":img}\n",
    "access_token = '24.6eb0719c0471fc3aece61a29bbe5b7b2.2592000.1613730251.282335-23568040'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'error_code': 6, 'error_msg': 'No permission to access data'}\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "车流统计\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/traffic_flow\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('车1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"area\":\"1,1,719,1,719,719,1,719\",\"case_id\":1,\"case_init\":\"false\",\"image\":img}\n",
    "access_token = '24.6eb0719c0471fc3aece61a29bbe5b7b2.2592000.1613730251.282335-23568040'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
